import java.util.Scanner;

 class Book {
    private static int count = 0; // 用于自动增长bookID的计数器
    private int bookID;
    private String bookName;
    private double price;
    private String author;

    // 构造代码块，用于自动增长bookID
    {
        bookID = ++count;
    }

    // 无参构造函数
    public Book() {
    }

    // 带bookName和author参数的构造函数
    public Book(String bookName, String author) {
        this.bookName = bookName;
        this.author = author;
    }

    // 带除bookID之外的所有属性参数的构造函数
    public Book(String bookName, double price, String author) {
        this.bookName = bookName;
        this.price = price;
        this.author = author;
    }

    // bookID的get方法
    public int getBookID() {
        return bookID;
    }

    // bookName的set和get方法
    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getBookName() {
        return bookName;
    }

    // price的set和get方法
    public void setPrice(double price) {
        this.price = price;
    }

    public double getPrice() {
        return price;
    }

    // author的set和get方法
    public void setAuthor(String author) {
        this.author = author;
    }

    public String getAuthor() {
        return author;
    }

    // toString方法
    @Override
    public String toString() {
        return "Book [bookID=" + bookID + ", bookName=" + bookName + ", price=" + price + ", author=" + author + "]";
    }
}



public class BookTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 假设用户输入要创建的Book对象数量
        Book[] books = new Book[n];

        // 初始化Book数组
        for (int i = 0; i < n; i++) {
            System.out.println("请输入第" + (i + 1) + "本书的书名：");
            String bookName = scanner.next();
            System.out.println("请输入第" + (i + 1) + "本书的价格：");
            double price = scanner.nextDouble();
            System.out.println("请输入第" + (i + 1) + "本书的作者：");
            String author = scanner.next();
            books[i] = new Book(bookName, price, author);
        }

        // 对Book数组按价格排序
        sortByPrice(books);

        // 打印排序后的Book数组
        System.out.println("排序后的书籍信息：");
        for (Book book : books) {
            System.out.println(book);
        }

        // 查找指定作者的Book信息
        System.out.println("请输入要查找的作者：");
        String searchAuthor = scanner.next();
        Book foundBook = searchByAuthor(books, searchAuthor);

        // 打印找到的Book信息
        if (foundBook != null) {
            System.out.println("找到指定作者的书籍信息：");
            System.out.println(foundBook);
        } else {
            System.out.println("未找到指定作者的书籍。");
        }

        scanner.close();
    }

    // 快速排序方法
    public static void sortByPrice(Book[] books) {
        quickSort(books, 0, books.length - 1);
    }

    private static void quickSort(Book[] books, int low, int high) {
        if (low < high) {
            int pivotIndex = partition(books, low, high);
            quickSort(books, low, pivotIndex - 1);
            quickSort(books, pivotIndex + 1, high);
        }
    }

    private static int partition(Book[] books, int low, int high) {
        Book pivot = books[high]; // 选择最右边的元素作为基准点
        int i = low - 1; // 指向小于基准值的最后一个元素的下一个位置

        for (int j = low; j < high; j++) {
            // 如果当前元素小于或等于基准值
            if (books[j].getPrice() <= pivot.getPrice()) {
                i++; // 增加小于基准值的元素计数
                // 交换当前元素和i指向的元素
                Book temp = books[i];
                books[i] = books[j];
                books[j] = temp;
            }
        }

        // 将基准值放到正确的位置
        Book temp = books[i + 1];
        books[i + 1] = pivot;
        books[high] = temp;

        // 返回基准值的索引
        return i + 1;
    }

    // 查找指定作者的Book信息，但不打印
    public static Book searchByAuthor(Book[] books, String author) {
        for (Book book : books) {
            if (book.getAuthor().equals(author)) {
                return book;
            }
        }
        return null; // 如果没有找到，则返回null
    }
}